package com.jcfk.eam.batch;

import com.jcfk.eam.service.mould.EamMouldEmailRecordService;
import com.jcfk.eam.service.mould.EamMouldPackageInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 定时任务启停控制器
 */
@ConditionalOnProperty(name = "app.mould-task.enable", havingValue = "true")
@Component
public class EamMouldEmailBatch {
    private final Logger logger = LoggerFactory.getLogger(EamMouldEmailBatch.class);

    @Autowired
    private EamMouldEmailRecordService eamMouldEmailRecordService;

    @Autowired
    private EamMouldPackageInfoService eamMouldPackageInfoService;

    /**
     * 定时发送邮件()
     */
//    @Scheduled(cron = "0 0 8 * * 1")
    @Scheduled(initialDelay = 60000, fixedDelay = 600000)
    public void checkMouldLife() {
        logger.info("checkMouldLife batch start...");
        eamMouldEmailRecordService.checkMouldLife();
        logger.info("checkMouldLife batch end");
    }

    /**
     * 模具框每月提醒/固定每月1号维修
     */
    @Scheduled(cron = "0 0 0 1 * ?")
    public void updateMouldPackAge() {
        logger.info("updateMouldPackAge batch start...");
        eamMouldPackageInfoService.updateMouldPackAge();
        logger.info("updateMouldPackAge batch end");
    }
}
